package com.local.seckill.service.impl;

import com.local.common.util.PageResultUtil;
import com.local.seckill.mapper.SeckillMapper;
import com.local.seckill.pojo.Seckill;
import com.local.seckill.service.SeckillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;


@Service
public class SeckillServiceImpl implements SeckillService {

    @Autowired
    private SeckillMapper seckillMapper;

    //查询数据列表，支持翻页和搜索
    @Override
    public PageResultUtil<Seckill> findSeckillList(Integer page, Integer limit, String sort, String order, Integer goodsId, Integer seckillStatus, String startTime, String endTime, Integer isDeleted) {
        Integer start = (page - 1) * limit;
        List<Seckill> seckillList = seckillMapper.findSeckillList(start, limit, sort, order, goodsId, seckillStatus, startTime, endTime, isDeleted);
        Integer totalSeckills = seckillMapper.getTotalSeckills(goodsId, seckillStatus, startTime, endTime, isDeleted);
        return new PageResultUtil<Seckill>(seckillList, totalSeckills, limit, page);
    }


    /**
     * 通过id查询
     * @param seckillId
     * @return
     */
    @Override
    public Seckill selectById(Integer seckillId) {
        return seckillMapper.selectById(seckillId);
    }


    /**
     * 新增
     * @param seckill
     * @return
     */
    @Override
    public Integer save(Seckill seckill) {
        return seckillMapper.save(seckill);
    }


    /**
     * 修改
     * @param seckill
     * @return
     */
    @Override
    public Integer update(Seckill seckill) {
        return seckillMapper.update(seckill);
    }


    /**
     * 逻辑删除
     * @param seckillId
     * @return
     */
    @Override
    public Integer delete(Integer seckillId) {
        return seckillMapper.delete(seckillId);
    }
}
